//
//  HEMenuPriceRangeCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/2.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMenuPriceRangeCell.h"

@interface HEMenuPriceRangeCell ()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *startTf;
@property (nonatomic, strong) UITextField *endTf;

@end

@implementation HEMenuPriceRangeCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
     
        [self initUI];
    }
    return self;
}

- (void)initUI {
    _startTf = [UITextField new];
    _startTf.backgroundColor = KHexColor(@"F1F3F8");
    _startTf.textAlignment = NSTextAlignmentCenter;
    _startTf.keyboardType = UIKeyboardTypeDecimalPad;
    _startTf.delegate = self;
    _startTf.tag = 10;
    [self.contentView addSubview:_startTf];
    
    _endTf = [UITextField new];
    _endTf.backgroundColor = KHexColor(@"F1F3F8");
    _endTf.textAlignment = NSTextAlignmentCenter;
    _endTf.keyboardType = UIKeyboardTypeDecimalPad;
    _endTf.delegate = self;
    _endTf.tag = 11;
    [self.contentView addSubview:_endTf];
    
    UILabel *splite = [UILabel new];
    splite.textAlignment = NSTextAlignmentCenter;
    splite.text = @"~";
    [self.contentView addSubview:splite];
    
    [_startTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(10);
        make.width.mas_offset(120);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
    
    [splite mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_startTf);
        make.left.equalTo(_startTf.mas_right).mas_offset(5);
        make.width.mas_offset(30);
    }];
    
    [_endTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(splite.mas_right).mas_offset(5);
        make.width.mas_offset(120);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
}

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

     NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
     if (textField.tag == 10) {
         _model.minPrice = text;
     }else if(textField.tag == 11) {
         _model.maxPrice = text;
     }
     return YES;
 }

- (void)setModel:(HEGoodsMenuModel *)model {
    _model = model;
    _startTf.text = model.minPrice;
    _endTf.text = model.maxPrice;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
